public class TestResource extends javax.swing.JFrame implements java.awt.event.ActionListener{
	
	private java.awt.Container contentPane;
	private String[] folderList;
	private String[][] fileList;
	private MyButton[] folderButtonList;
	private MyButton[][] fileButtonList;

	private javax.swing.JPanel folderPanel = new javax.swing.JPanel();
	private javax.swing.JPanel filePanel = new javax.swing.JPanel();
	private TextProcessorPanel textProcessorPanel = new TextProcessorPanel();
	private javax.swing.JScrollPane scrollPane = new javax.swing.JScrollPane(textProcessorPanel);
	
	private javax.swing.JPanel tempPanel = new javax.swing.JPanel();
	

	private javax.swing.JButton button = new javax.swing.JButton("test me!");
	
	public TestResource(){
		super("testResource v15");
		contentPane = getContentPane();
		loadFolder();
		folderButtonList = new MyButton[folderList.length];

		for(int i=0; i<folderButtonList.length; i++){
			folderButtonList[i] = new MyButton(folderList[i]);
			folderButtonList[i].addActionListener(this);
			folderPanel.add(folderButtonList[i]);
		}

		loadFile();
		fileButtonList = new MyButton[fileList.length][];
		filePanel.setLayout(new java.awt.GridLayout(0,1));

		for(int i=0; i<fileList.length; i++){
			fileButtonList[i] = new MyButton[fileList[i].length];
			for(int ii=0; ii<fileList[i].length; ii++){
				fileButtonList[i][ii] = new MyButton(fileList[i][ii].substring(0,fileList[i][ii].lastIndexOf(".")));
				fileButtonList[i][ii].addActionListener(this);
			}
		}
		
		folderPanel.setBackground(new java.awt.Color(200,250,250));
		filePanel.setBackground(new java.awt.Color(200,250,250));
		tempPanel.setBackground(new java.awt.Color(200,250,250));
		
		tempPanel.add(filePanel);
		add(folderPanel,java.awt.BorderLayout.NORTH);
		add(tempPanel,java.awt.BorderLayout.WEST);
		add(scrollPane);

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setVisible(true);
		this.setBounds(50,50,800,600);
		
	}

	public void actionPerformed(java.awt.event.ActionEvent e){
		for(int i=0; i<folderList.length; i++){
			if(e.getSource() == folderButtonList[i]){
				filePanel.removeAll();
				filePanel.repaint();
				for(int ii=0; ii<fileList[i].length; ii++){
					filePanel.add(fileButtonList[i][ii]);
				}
				pack();
			}
		}
		for(int i=0; i<fileList.length; i++){
			for(int ii=0; ii<fileList[i].length; ii++){
				if(e.getSource() == fileButtonList[i][ii]){
					readFile("./Resource/"+folderList[i]+"/"+fileList[i][ii]);
				}
			}
		}
	}

	public void loadFolder(){
		java.io.File currentDirectory = new java.io.File("./Resource");
		folderList = currentDirectory.list();
	}
	
	public void loadFile(){
		fileList = new String[folderList.length][];
		java.io.File currentDirectory;
		for(int i=0; i<folderList.length; i++){
			currentDirectory = new java.io.File("./Resource/"+folderList[i]);
			fileList[i] = currentDirectory.list();
		}
	}
	
	public void readFile(String fileName){
		textProcessorPanel.setFileName(fileName);
		textProcessorPanel.repaint();
		contentPane.repaint();
		pack();
	}

	public static void main(String para[]){
		TestResource app = new TestResource();
		
	}

}